//
//  MainDetailHavePicCell.m
//  Daybook
//
//  Created by dllo on 16/5/26.
//  Copyright © 2016年 zhangbin. All rights reserved.
//

#import "MainDetailHavePicCell.h"
#import "Common.h"
#import "AccountBook.h"

@interface MainDetailHavePicCell ()

@property (nonatomic, strong)UIView *lineView;

@property (nonatomic, strong)UIImageView *pointImageView;

@end

@implementation MainDetailHavePicCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
        
        
        
    }
    return self;
}

- (void)createView {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.lineView = [[UIView alloc]init];
    self.lineView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.lineView];
    
    
    self.pointImageView = [[UIImageView alloc]init];
    self.pointImageView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.pointImageView];
    self.pointImageView.image = [UIImage imageNamed:@"pointImage"];
    
    
    self.dateLabel = [[UILabel alloc]init];
    self.dateLabel.backgroundColor= [UIColor whiteColor];
    [self.contentView addSubview:self.dateLabel];
    self.dateLabel.font = [UIFont systemFontOfSize:12];
    self.dateLabel.textAlignment = 2;
    
    
    self.picImageView = [[UIImageView alloc]init];
    self.picImageView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.picImageView];
    
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameLabel];
    self.nameLabel.font = [UIFont systemFontOfSize:12];
    
    
    
    self.photoImageView = [[UIImageView alloc]init];
    self.photoImageView.backgroundColor =[UIColor whiteColor];
    [self.contentView addSubview:self.photoImageView];
    self.photoImageView.layer.cornerRadius = 10;
    self.photoImageView.layer.masksToBounds = YES;
    
    
    
    
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.lineView.frame = CGRectMake(MAIN_WIDTH / 2, 0, 1, MAIN_HEIGHT);
    self.pointImageView.frame = CGRectMake(MAIN_WIDTH / 2 - 9,  90 / 414.0 *MAIN_WIDTH, 20 / 414.0 *MAIN_WIDTH, 20 / 414.0 *MAIN_WIDTH);
    
    self.picImageView.frame = CGRectMake(MAIN_WIDTH / 2 - 20 / 414.0 *MAIN_WIDTH, 110 / 414.0 *MAIN_WIDTH, 40 / 414.0 *MAIN_WIDTH, 40 / 414.0 *MAIN_WIDTH);
    self.dateLabel.frame = CGRectMake(MAIN_WIDTH / 2 - 50, 90 / 414.0 *MAIN_WIDTH, 40 / 414.0 *MAIN_WIDTH, 20 / 414.0 *MAIN_WIDTH);
    
    self.nameLabel.frame = CGRectMake(MAIN_WIDTH / 2 - 40 / 414.0 *MAIN_WIDTH, 150 / 414.0 *MAIN_WIDTH, 80 / 414.0 *MAIN_WIDTH, 20 / 414.0 *MAIN_WIDTH);
    
    self.photoImageView.frame = CGRectMake((MAIN_WIDTH - 300 * self.photoImageView.image.size.width / self.photoImageView.image.size.height) / 2, 170,300 * self.photoImageView.image.size.width / self.photoImageView.image.size.height, 300);

    
    
    
}

- (void)setAccountBook:(AccountBook *)accountBook {
    _accountBook = accountBook;
    self.picImageView.image = [UIImage imageNamed:_accountBook.picName];
    self.dateLabel.text = [NSString stringWithFormat:@"%@日", [[NSString stringWithFormat:@"%@", _accountBook.time ] substringWithRange:NSMakeRange(8, 2)]];
    self.photoImageView.image = [UIImage imageWithData:_accountBook.imageData];
//    self.photoImageView.frame = CGRectMake(0, 0,200 * self.photoImageView.image.size.width / self.photoImageView.image.size.height, 200);
//    self.photoImageView.center = CGPointMake(MAIN_WIDTH / 2, 170 / 736.0 *MAIN_HEIGHT + self.photoImageView.image.size.height / 2 / 736.0 *MAIN_HEIGHT);
    
    
    if (_accountBook.money == 0) {
        self.nameLabel.text = [NSString stringWithFormat:@"%@ %.2lf", _accountBook.name, [_accountBook.income floatValue]];
    }else {
        self.nameLabel.text = [NSString stringWithFormat:@"%@ %.2lf", _accountBook.name, [_accountBook.money floatValue]];
    }
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
